echo 'fetchremotehash';
#$METADATA_DIR
cd $LOCALDIR
cd $METADATA_DIR
##FTPUSER=testftp
##REMOTEDIR=/
##LOCALDIR=~/tblog
##FTPHOSTNAME=localhost
##SALT=CarrieIsMyWife
ncftpget -c  -u$FTPUSER -p$PASSWORD $FTPHOSTNAME $METADATA_DIR/$CHF > $RHF
exit_code=$?;
if [ $exit_code -eq 1 ] ; then
    echo 'Could not connect to remote host.'
    exit 1
fi
if [ $exit_code -eq 2 ] ; then 
    echo 'Could not connect to remote host - timed out.'
    exit 1;
fi
if [ $exit_code -eq 3 ] ; then
    echo 'Transfer Failed, if there is no canonical hash file then you should upload the entire ftpsite with the metadata directory.'
    echo 'Renaming local hashfile to canonical.'
    mv $NHF $CHF
    echo 'State ready for initial seeding of sync protocol.';
    exit 1 
fi
if [ $exit_code -ge 4 ] ; then
    echo 'Cannot fetch cannonical file, probable ftp server issue.';
    echo 'Also confirm the configuration file host name is correct, and confirm ncftp is working correctly.'
    exit 1;
fi
